package com.test;


/*
public class Example01 {
    public static void main(String[] args){
        ArrayList list=new ArrayList();
        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
        list.add("zhaoliu");
        System.out.println("集合的长度:"+list.size());
        System.out.println("第二个元素是:"+list.get(1));
        list.remove(3);
        System.out.println("删除索引为3的元素:"+list);
        list.set(1,"lisi2");
        System.out.println("替换索引1的元素为lisi2"+list);

    }
}


 */

/*
import java.util.LinkedList;


public class Example01 {
    public static void main(String[] args){
        LinkedList link=new LinkedList();       //创建LinkedList集合
        link.add("zhangsan");
        link.add("lisi");
        link.add("wangwu");
        link.add("zhaoliu");
        System.out.println(link.toString());        //获取并打印该集合中的元素;
        link.add(3,"pinru");
        link.addFirst("first");
        System.out.println(link);
        System.out.println(link.getFirst());        //取出link集合中第一个元素
        link.remove(3);
        link.removeFirst();
        System.out.println(link);
    }
}


 */

/*
import java.util.ArrayList;
import java.util.Iterator;

public class Example01 {
    public static void main(String[] args) {
        ArrayList list=new ArrayList();
        list.add("zhangsan");
        list.add("lisi");
        list.add("wangwu");
        list.add("zhaoliu");
        Iterator it=list.iterator();    //获取Iterator对象
        while (it.hasNext()){
            Object obj=it.next();       //若ArrayList集合中有下一个元素,则取出来
            System.out.println(obj);
        }
    }
}

 */

// Iterator对集合中的元素进行遍历时,如果调用了集合对象remove()方法删除元素,然后继续使用Iterator遍历元素会出现异常

/*
import java.util.ArrayList;
import java.util.Iterator;

public class Example01 {
    public static void main(String[] args){
        ArrayList list = new ArrayList();    //创建ArrayList集合
        list.add("张三");
        list.add("李四");
        list.add("王五");
        Iterator it=list.iterator();    //获取Iterator对象
        while(it.hasNext()){
            Object obj=it.next();
            if("张三".equals(obj)){
//                list.remove(obj);
//                break;        //第一种方法加break;
                it.remove();    //第二种方法删除它
            }
        }
        System.out.println(list);
    }
}

 */


// for(容量中元素类型 临时变量: 容器变量)
/*
import java.util.ArrayList;

public class Example01 {
    public static void main(String[] args){
        ArrayList list=new ArrayList();
        list.add("张三");			        // 向ArrayList集合中添加字符串元素
        list.add("李四");
        list.add("王五");
        for (Object obj:list){
            System.out.println(obj);        //取出并打印ArrayList集合中的对象
        }
    }
}
 */

/*
public class Example01 {
    static String[] strList = {"aaa", "bbb", "ccc"};

    public static void main(String[] args) {
        //foreach循环遍历数组
        for (String str : strList) {
            str = "ddd";
        }
        System.out.println("foreach循环修改后的数组:"+strList[0]+","+strList[1]+","+strList[2]);
        //for循环遍历数组
        for(int i=0;i<strList.length;i++){
            strList[i]="dddd";
        }
        System.out.println("普通for循环修改后的数组:"+strList[0]+","+strList[1]+","+strList[2]);
    }
}

 */

/*
import java.util.HashSet;
import java.util.Iterator;

public class Example01 {
    public static void main(String[] args) {
        HashSet hset = new HashSet();   // 创建HashSet集合
        hset.add("张三");                  // 向该Set集合中添加字符串
        hset.add("李四");
        hset.add("王五");
        hset.add("李四");                 //向Set集合中添加字符串
        Iterator it=hset.iterator();       //获取Iterator对象
        while (it.hasNext()){
            Object obj=it.next();
            System.out.println(obj);
        }
    }
}
 */

/*
import java.util.HashSet;

class Student {
    String id;
    String name;

    public Student(String id, String name) {
        this.name = name;
        this.id = id;
    }

    public String toString() {       //重写toString()方法
        return id + ":" + name;
    }
}

public class Example01 {
    public static void main(String[] args){
        HashSet hs=new HashSet();
        Student stu1=new Student("A","张三");
        Student stu2=new Student("B","lisi");
        Student stu3=new Student("C","lisi");
        hs.add(stu1);
        hs.add(stu2);
        hs.add(stu3);
        System.out.println(hs);
    }
}

 */


/*
import java.util.HashSet;

class Student {
    private String id;
    private String name;

    public Student(String id, String name) {
        this.id = id;
        this.name = name;
    }
    //重写toString()方法
    public String toString() {
        return id + ":" + name;
    }
    //重写hashCode方法
    public int hashCode(){
        return id.hashCode();       //返回id属性的哈希值
    }
    //重写equals方法
    public boolean equals(Object obj){
        if(this==obj){
            return true;
        }
        if(!(obj instanceof Student)){
            //判断对象为Student类型
            return false;
        }
        Student stu=(Student) obj;      //对象强转为Student类型
        boolean b=this.id.equals(stu.id);
        return b;
    }
}

public class Example01 {
    public static void main(String[] args){
        HashSet hs=new HashSet();       //创建HashSet对象
        Student stu1=new Student("1","zhangsan");
        Student stu2=new Student("2","lisi");
        Student stu3=new Student("2","lisi");
        hs.add(stu1);
        hs.add(stu2);
        hs.add(stu3);
        System.out.println(hs);
        //[1:zhangsan, 2:lisi]  后两个的哈希值一样,HashSet认为这两个对象相同
    }
}

 */

/*
import java.util.Iterator;
import java.util.LinkedHashSet;

public class Example01 {
    public static void main(String[] args){
        LinkedHashSet set=new LinkedHashSet();
        set.add("zhangsan");
        set.add("lisi");
        set.add("wangwu");
        Iterator it=set.iterator();     //获得Iterator对象
        while (it.hasNext()){
            Object obj=it.next();
            System.out.println(obj);
        }
    }
}

 */

/*
import java.util.TreeSet;

public class Example01 {
    public static void main(String[] args){
        TreeSet ts=new TreeSet();
        ts.add(3);
        ts.add(29);
        ts.add(101);
        ts.add(21);
        System.out.println("创建好的TreeSet集合为:"+ts);
        //首尾元素
        System.out.println("TreeSet集合首元素为:"+ts.first());
        System.out.println("TreeSet集合尾部元素为:"+ts.last());
        //比较元素
        System.out.println("集合中小于或等于9的最大的一个元素为:"+ts.floor(9));
        System.out.println("集合中大于10的最小的一个元素为:"+ts.higher(10));
        System.out.println("集合中大于100的最小的一个元素为:"+ts.higher(100));
        //删除元素
        Object first=ts.pollFirst();
        System.out.println("删除的第一个元素是:"+first);
        System.out.println("删除第一个元素后TreeSet集合为:"+ts);
    }
}




import java.util.TreeSet;

class Student implements Comparable {
    private String name;
    private int age;
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }
    //重写toString()方法
    public String toString(){
        return name+":"+age;
    }
    //重写Comparable接口的compareTo()方法
    public int compareTo(Object obj){
        Student stu=(Student)obj;
        if(this.age- stu.age>0){
            return 1;
        }
        if(this.age- stu.age==0){
            return this.name.compareTo(stu.name);
        }
        return -1;
    }
}
public class Example01 {
    public static void main(String[] args){
        TreeSet ts=new TreeSet();
        ts.add(new Student("Lucy",18));
        ts.add(new Student("Tom",20));
        ts.add(new Student("Bob",20));
        ts.add(new Student("Tom",20));
        System.out.println(ts);
        //[Lucy:18, Bob:20, Tom:20]
        //重复的元素被去掉了
    }
}

 */

/*
import java.util.Comparator;
import java.util.TreeSet;

class Student {
    private String id;
    private String name;

    public Student(String id, String name) {
        this.id = id;
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String toString() {
        return id + ":" + name;
    }
}

public class Example01 {
    public static void main(String[] args) {
        TreeSet ts = new TreeSet(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Student stu1 = (Student) o1;
                Student stu2 = (Student) o2;
                if (!stu1.getId().equals(stu2.getId())) {
                    return stu1.getId().compareTo(stu2.getId());
                } else {
                    return stu1.getName().compareTo(stu2.getName());
                }
            }
        });
        ts.add(new Student("2", "Mary"));    //向ts集合中添加元素
        ts.add(new Student("1", "Jack"));
        ts.add(new Student("3", "Lisa"));
        ts.add(new Student("2", "Lily"));
        System.out.println(ts);
    }
}

 */

/*
import java.util.HashMap;
import java.util.Map;

public class Example01{
    public static void main(String[] args){
        Map map=new HashMap();
        map.put("1","张三");
        map.put("2","李四");
        map.put("3","王五");
        System.out.println("1:"+map.get("1"));
        System.out.println("2:"+map.get("2"));
        System.out.println("3:"+map.get("3"));
    }
}

 */

/*
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Example01 {
    public static void main(String[] args){
        Map map = new HashMap();
        map.put("1","张三");  //存储键和值
        map.put("2","李四");
        map.put("3","王五");
        Set keySet=map.keySet();;   //获取键的集合
        Iterator it=keySet.iterator();      //获取Iterator对象
        while(it.hasNext()){
            Object key=it.next();
            Object value=map.get(key);      //获取每个键所对应的值
            System.out.println(key+":"+value);
        }
    }
}

 */

import java.util.HashMap;
import java.util.Map;

public class Example01 {
    public static void main(String[] args){
        Map map=new HashMap();
        map.put("1","zhangsan");
        map.put("2","lisi");
        map.put("3","wangwu");
    }
}


//（1）包名中所有字母小写
//
//（2）类名和接口名的每个首字母都大写，ArrayList
//
//（3）常量名中所有字母都大写，单词之间用下画线连接，DAY_OF_MONTH
//
//（4）变量名和方法名的第一个单词首字母小写，从第二个单词开始每个单词首字母大写，lineNumber，getLineNumber
//
//（5）在程序中，尽量使用有意义的英文单词定义标识符，使程序便于阅读，userName定义用户，password定义密码


